package com.javafactroy.kunlong;

import ch.qos.logback.classic.Logger;
import com.github.jsonzou.jmockdata.JMockData;
import com.github.jsonzou.jmockdata.MockConfig;
import com.javafactroy.kunlong.api.dto.EmployeeApiDto;
import com.javafactroy.kunlong.api.openfeign.EmployeeOpenApiWebLocal;
import com.javafactroy.kunlong.api.openfeign.EmployeeOpenApiWebRemote;

import dto.feign.client.com.javafactroy.kunlong.ApiPageInfo;
import dto.feign.client.com.javafactroy.kunlong.ApiResult;
import utils.com.javafactroy.kunlong.common.CommonUtils;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.junit.jupiter.api.*;

/**
 * @author raymond.lei@163.com
 * @date 2023-11-11 12:35:27
 */

@ExtendWith(SpringExtension.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(MethodOrderer.MethodName.class)
@SpringBootTest(classes = {WebDbAgent.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class EmployeeTestOpenWeb {
    Logger log = (Logger) LoggerFactory.getILoggerFactory().getLogger("ROOT");

    @BeforeEach
    void setUp() {
        log.info("setUp{}", "...");
    }

    @AfterEach
    void tearDown() {
        log.info("tearDown{}", "...");
    }

    String pkeyField = "id";

    public EmployeeApiDto mock() {
        MockConfig mockConfig = new MockConfig()
                .doubleRange(1e-9, 1111222221119999.99999d)
                .floatRange(1e-8f, 111111122221119999.99999f)
                .decimalScale(52).excludes("emps", pkeyField, "orderBys")
                .subConfig("status").intRange(0, 9).globalConfig();
        EmployeeApiDto entity = JMockData.mock(EmployeeApiDto.class, mockConfig);
        log.info("mock entity = {}", CommonUtils.toJSONString(entity));
        return entity;
    }


    @Autowired
    EmployeeOpenApiWebLocal web;

    @Autowired
    EmployeeOpenApiWebRemote webRemote;

    @Test
    public void test001_query() {
        ApiResult<ApiPageInfo<EmployeeApiDto>> apiResult = web.query(new EmployeeApiDto());
        log.info("query apiResult = {}", apiResult);

    }

    @Test
    public void test002_selectByPkey() {
        ApiResult<EmployeeApiDto> list = web.selectByPkey(1l);
        log.info("list={}",CommonUtils.toJSONString(list));

    }

    @Test
    public void test003_save() {

        EmployeeApiDto entity = mock();

        web.save(entity);
        log.info("save entity = {}", CommonUtils.toJSONString(entity));

    }
}
